package com.stb.isharemessage.ui.feed;

//package com.immomo.momo.android.activity;

import java.util.ArrayList;


import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;



import java.util.List;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.StringUtils;



















//import com.allen.ui.profile.ProfileActivity;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.LocationClientOption.LocationMode;
import com.speed.im.login.EncryptionUtil;
import com.spice.im.BaseActivity;
import com.spice.im.ContactFrameActivity;
import com.spice.im.OtherProfileActivity;
import com.spice.im.R;
import com.spice.im.SpiceApplication;
import com.spice.im.group.GroupDetailsActivity;
import com.spice.im.group.ViewGroupMemberIQ;
import com.spice.im.group.ViewGroupMemberIQResponse;
import com.spice.im.group.ViewGroupMemberIQResponseProvider;
import com.spice.im.preference.PreferenceActivity;
import com.spice.im.preference.PreferenceActivity.exPhoneCallListener;
import com.spice.im.utils.Feed;
import com.spice.im.utils.HeaderLayout;
import com.spice.im.utils.HeaderLayout.HeaderStyle;
import com.spice.im.utils.HeaderLayout.onMiddleImageButtonClickListener;
import com.spice.im.utils.HeaderLayout.onRightImageButtonClickListener;
import com.stb.core.chat.ContactGroup;
//import com.stb.isharemessage.R;
//import com.stb.isharemessage.ui.GpsSearchResPullRefListActivity.MyOnRefreshListener2;
import com.stb.isharemessage.service.aidl.IXmppFacade;
//import com.example.android.bitmapfun.util.AsyncTask;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.stb.isharemessage.BeemApplication;
import com.stb.isharemessage.BeemService;
import com.stb.isharemessage.IConnectionStatusCallback;
//import com.stb.isharemessage.service.DynamicsItemParcelable;
//import com.stb.isharemessage.service.MyHashMap;
//import com.stb.isharemessage.ui.AddDynamicsActivity;
//import com.stb.isharemessage.ui.ContactFrameActivity;
//import com.stb.isharemessage.ui.ContactListPullRefListActivity;
//import com.stb.isharemessage.ui.ChatPullRefListActivity.MyLocationListener;
//import com.stb.isharemessage.ui.profile.GroupProfileActivity;
//import com.stb.isharemessage.ui.profile.OtherProfileActivity;
//import com.stb.isharemessage.ui.register.BaseActivity;
//import com.stb.isharemessage.ui.register.FlippingLoadingDialog;
import com.stb.isharemessage.utils.BeemBroadcastReceiver;
import com.stb.isharemessage.utils.BeemConnectivity;
//import com.stb.isharemessage.utils.Feed;
//import com.stb.isharemessage.utils.FeedComment;
//import com.stb.isharemessage.utils.HeaderLayout;
//import com.stb.isharemessage.utils.JsonResolveUtils;
//import com.stb.isharemessage.utils.HeaderLayout.HeaderStyle;
//import com.stb.isharemessage.utils.HeaderLayout.onMiddleImageButtonClickListener;
//import com.stb.isharemessage.utils.HeaderLayout.onRightImageButtonClickListener;
import com.spice.im.utils.AsyncTask;


















import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
//import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

//import com.immomo.momo.android.BaseActivity;
////import com.immomo.momo.android.R;
//import com.immomo.momo.android.adapter.OtherFeedListAdapter;
//import com.immomo.momo.android.entity.Feed;
//import com.immomo.momo.android.entity.NearByPeople;
//import com.immomo.momo.android.entity.NearByPeopleProfile;
//import com.immomo.momo.android.util.JsonResolveUtils;
//import com.immomo.momo.android.view.HeaderLayout;
//import com.immomo.momo.android.view.HeaderLayout.HeaderStyle;
//import com.immomo.momo.android.view.MoMoRefreshListView;
//import com.immomo.momo.android.view.MoMoRefreshListView.OnCancelListener;
//import com.immomo.momo.android.view.MoMoRefreshListView.OnRefreshListener;

public class OtherFeedListActivity extends BaseActivity  implements IConnectionStatusCallback,OnClickListener{//implements OnCancelListener,OnRefreshListener, 

    private static final Intent SERVICE_INTENT = new Intent();
    static {
    	SERVICE_INTENT.setComponent(new ComponentName("com.spice.im", "com.stb.isharemessage.BeemService"));//自身应用pkg名称，非service所在pkg名称
    }
	private IXmppFacade mXmppFacade;
	private boolean mBinded = false;
	private Context mContext;
	private final ServiceConnection mServConn = new BeemServiceConnection(this);
//	private final BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver();//原来的网络状态注释掉
	
	private HeaderLayout mHeaderLayout;
	private PullToRefreshListView mMmrlvList;
	private OtherFeedListAdapter mAdapter;
//	private NearByPeople mPeople;
//	private NearByPeopleProfile mProfile;
	
	

	private List<Feed> mFeeds = new ArrayList<Feed>();
	private List<Feed> mFeeds_temp = new ArrayList<Feed>();
	public void clearComments(){
		mFeeds.clear();
    }
    public void addItem(List<Feed> datas) {
    	if(datas!=null){
//    		mComments.clear();
        	for (Feed info : datas) {
        		mFeeds.add(info);
            }
    	}
    }
    
    //网络状态start
	private View mNetErrorView;
	private TextView mConnect_status_info;
	private ImageView mConnect_status_btn;
    private exPhoneCallListener myPhoneCallListener = null;
    private TelephonyManager tm = null;
    //网络状态end

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		mContext = this;
		setContentView(R.layout.activity_otherfeedlist);
//		this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));//原来的网络状态注释掉
		initViews();
		initEvents();
		init();
		
        //网络状态start
        mNetErrorView = findViewById(R.id.net_status_bar_top);
        mConnect_status_info = (TextView)mNetErrorView.findViewById(R.id.net_status_bar_info_top2);
        mConnect_status_btn = (ImageView)mNetErrorView.findViewById(R.id.net_status_bar_btn);
        mConnect_status_btn.setOnClickListener(this);
        
	    IntentFilter mFilter = new IntentFilter();
	    mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); // 添加接收网络连接状态改变的Action
	    registerReceiver(mNetWorkReceiver, mFilter);
        /* 添加自己实现的PhoneStateListener */
        myPhoneCallListener = new exPhoneCallListener();
       
       /* 取得电话服务 */
        tm =(TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
       
        /* 注册电话通信Listener */
        tm.listen(myPhoneCallListener,PhoneStateListener.LISTEN_CALL_STATE);
	    //网络状态end
		
		// 获取当前用户位置
		mLocationClient = new LocationClient(getApplicationContext());
		mMyLocationListener = new MyLocationListener();
		mLocationClient.registerLocationListener(mMyLocationListener);
//		mGeofenceClient = new GeofenceClient(getApplicationContext());
		InitLocation();
		showLoadingDialog("正在定位,请稍候...");
		mLocationClient.start();
		if (mLocationClient != null && mLocationClient.isStarted())
		mLocationClient.requestOfflineLocation();
		
		
		
		BeemApplication.getInstance().addActivity(this);
	}
	public void onClick(View v) {
		switch (v.getId()) {
		//网络设置
        case R.id.net_status_bar_btn:
			setNetworkMethod(this);
		break;
		}
	}
	@Override
	protected void initViews() {
		mHeaderLayout = (HeaderLayout) findViewById(R.id.otherfeedlist_header);
//		mHeaderLayout.init(HeaderStyle.DEFAULT_TITLE);
//		mHeaderLayout.init(HeaderStyle.TITLE_RIGHT_IMAGEBUTTON);
		mMmrlvList = (PullToRefreshListView) findViewById(R.id.ptrlvHeadLineNews);
		
//		mMmrlvList.setOnItemClickListener(mOnContactClick);
//      ptrlv.setOnLongClickListener(mOnContactLongClick);
		mMmrlvList.setMode(Mode.BOTH);
		mMmrlvList.setOnRefreshListener(new MyOnRefreshListener2());
	}

	@Override
	protected void initEvents() {
//		mMmrlvList.setOnRefreshListener(this);
//		mMmrlvList.setOnCancelListener(this);
	}

	private void init() {
//		mMmrlvList.setItemsCanFocus(false);
//		mProfile = getIntent().getParcelableExtra("entity_profile");
//		mPeople = getIntent().getParcelableExtra("entity_people");
//		mHeaderLayout.setDefaultTitle(mProfile.getName() + "的动态", null);
//		mHeaderLayout.setDefaultTitle("的动态", null);
//		getStatus();
		mAdapter = new OtherFeedListAdapter(OtherFeedListActivity.this,OtherFeedListActivity.this,
				mFeeds);
		mMmrlvList.setAdapter(mAdapter);
//		mAdapter.notifyDataSetChanged();//20141216 added by allen
	}
    private int mType = 0;//1 pulldown 2 pullup
    
	class MyOnRefreshListener2 implements OnRefreshListener2<ListView> {

//		private PullToRefreshListView mPtflv;

		public MyOnRefreshListener2() {
//			this.mPtflv = ptflv;
		}

		@Override
		public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
			// 下拉刷新
			String label = DateUtils.formatDateTime(getApplicationContext(),
					System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME
							| DateUtils.FORMAT_SHOW_DATE
							| DateUtils.FORMAT_ABBREV_ALL);

			refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
			
			if(currentPage>0){
				--currentPage;
				mType = 2;
				flag = false;
//				LoadMore();
				getStatus();
			}
			else if(currentPage == 0){
				mHandler2.sendEmptyMessage(1);
			}
		}

		@Override
		public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
			// 上拉加载
			if(currentPage == pageCount){
				mHandler2.sendEmptyMessage(2);
			}
			else if(currentPage < pageCount){
			    ++currentPage;	
				mType = 1;
				flag = false;
//				LoadMore();
				getStatus();
			}else//up and down临界状态:如已经到底端了，此时下拉currentPage == 0
				mHandler2.sendEmptyMessage(2);
		}

	}
	
	private boolean flag = false;
//	public void LoadMore(){
//		putAsyncTask(new AsyncTask<Void, Void, Boolean>() {
//
//			@Override
//			protected void onPreExecute() {
//				super.onPreExecute();
//				if(flag)
//				showLoadingDialog("正在加载,请稍后...");
//			}
//
//			@Override
//			protected Boolean doInBackground(Void... params) {
//				initContactList();
//				return true;
//			}
//
//			@Override
//			protected void onPostExecute(Boolean result) {
//				super.onPostExecute(result);
//				dismissLoadingDialog();
//				if (!result) {
//					showCustomToast("数据加载失败...");
//					mHandler2.sendEmptyMessage(3);
//				} else {
//					mHandler2.sendEmptyMessage(0);
//				}
////				ptrstgv.getRefreshableView().hideFooterView();
//			}
//
//		});
//	}
	Handler mHandler2 = new Handler() {

		@Override
		public void handleMessage(android.os.Message msg) {
			super.handleMessage(msg);
			Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++ismyself1="+ismyself+" handler1");
//			if(ismyself){
//				Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++ismyself2="+ismyself+" handler2");
//    			mHeaderLayout.init(HeaderStyle.TITLE_CHAT);
//    			mHeaderLayout.setTitleChat(R.drawable.ic_chat_dis_1,
//    					R.drawable.bg_chat_dis_active, StringUtils.parseName(otherusername)+"的动态",
//    					BeemApplication.getInstance().mGpsAddr,
//    					R.drawable.addynamics,//ic_menu_invite  ic_topbar_profile
//    					new OnMiddleImageButtonClickListener(),
//    					R.drawable.return2,
//    					new OnRightImageButtonClickListener());
//			}
			switch (msg.what) {
			case 0:
				if(errorType==5){
					
					int atIndex = otherusername.lastIndexOf("@");
		    		if(atIndex<0)
		    			;
		    		else
		    			otherusername = StringUtils.parseName(otherusername);
		    		
//					mAdapter = new OtherFeedListAdapter(OtherFeedListActivity.this,OtherFeedListActivity.this,otherusername,
//							mFeeds,mtype);
					addItem(mFeeds_temp);
//					mMmrlvList.setAdapter(mAdapter);
					mAdapter.notifyDataSetChanged();//20141216 added by allen
				}else{
//					Toast.makeText(GpsSearchResPullRefListActivity.this,errorMsg[errorType], 1000).show();
					showCustomToast(errorMsg[errorType]);
				}
				mMmrlvList.onRefreshComplete();
				mType = 0;
//				mMmrlvList.onRefreshComplete();
				break;

			case 1:
				mType = 0;
				mMmrlvList.onRefreshComplete();
				showCustomToast("已达顶端!");
				break;
			case 2:
				mType = 0;
				mMmrlvList.onRefreshComplete();
				showCustomToast("已达底端!");
				break;
			case 8://定位成功
				mLocationClient.stop();
//				mHeaderLayout.setDefaultTitle("附近", mGpsAddr);
//				getContactList();
				getStatus();
				break;
			case 9://定位失败
				mLocationClient.stop();
//				mHeaderLayout.setDefaultTitle("附近", mGpsAddr);
//				getContactList();
				mType = 0;
				mMmrlvList.onRefreshComplete();
				break;				
			default:
				mType = 0;
				mMmrlvList.onRefreshComplete();
				break;
			}
		}

	};
	private void getStatus() {
		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++getStatus="+otherusername);
//		if (mFeeds == null) {
			putAsyncTask(new AsyncTask<Void, Void, Boolean>() {

				@Override
				protected void onPreExecute() {
					super.onPreExecute();
					showLoadingDialog("正在加载,请稍后...");
				}

				@Override
				protected Boolean doInBackground(Void... params) {
//					mFeeds = new ArrayList<Feed>();
//					return JsonResolveUtils.resolveNearbyStatus(
//							OtherFeedListActivity.this, mFeeds,
//							"momo_p_001");//mProfile.getUid()
					return InitialFeeds2();
				}

				@Override
				protected void onPostExecute(Boolean result) {
					super.onPostExecute(result);
					dismissLoadingDialog();
					if (!result) {
						showCustomToast("数据加载失败...");
						mHandler2.sendEmptyMessage(3);
					} else {
//						mAdapter = new OtherFeedListAdapter(OtherFeedListActivity.this,OtherFeedListActivity.this,otherusername,
//								mFeeds);
//						mMmrlvList.setAdapter(mAdapter);
//						mMmrlvList.onRefreshComplete();
						mHandler2.sendEmptyMessage(0);
					}
				}

			});
//		}
	}
	private String otherusername = "";
//	private MyHashMap myHashMap = null;
	private HashMap hashMap = null;
//	private List<DynamicsItemParcelable> results = null;
//	private DynamicsItemParcelable dynamicsItemParcelable = null;
	private List<DynamicsItem> results = null;
	private DynamicsItem dynamicsItem = null;
	private Feed feed = null;
	private int CTTotal = 0;//总条数
	private int totalnumber = 0;//本次查询返回条数
	
    private int currentPage = 0;
    private int numberresult = 50;
    private int pageCount = 0;//总页数
	
    private String username2 = "";
    private boolean ismyself = false;
    private String mtype = "";
//	public boolean InitialFeeds(){
//		mFeeds_temp.clear();
//		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++InitialFeeds="+otherusername);
//		if(BeemConnectivity.isConnected(getApplicationContext())){
//		    try {
//		    	if(mXmppFacade!=null){
//			    	if (mXmppFacade.getXmppConnectionAdapter()!=null 
//							&& mXmppFacade.getXmppConnectionAdapter().getAdaptee()!=null
//							&& mXmppFacade.getXmppConnectionAdapter().getAdaptee().isConnected() 
//			    			&& mXmppFacade.getXmppConnectionAdapter().getAdaptee().isAuthenticated()
//			    			&& mXmppFacade.getXmppConnectionAdapter().getAdaptee().isAlive()){
//			    		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++InitialFeeds1 otherusername="+otherusername);
////			    		mtype = "2";
//			    		if(mtype==null 
//			    				|| mtype.equalsIgnoreCase("null")
//			    				|| mtype.length()==0)
//			    			mtype = "2";
//			    		String dynamicid = "";
//			    		username2 = StringUtils.parseName(mXmppFacade.getXmppConnectionAdapter().getJID());
//			    		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++InitialFeeds1 username2="+username2);
//			    		if(username2.equals(StringUtils.parseName(otherusername))){
//			    			ismyself = true;
////			    			mHeaderLayout.init(HeaderStyle.TITLE_CHAT);
////			    			mHeaderLayout.setTitleChat(R.drawable.ic_chat_dis_1,
////			    					R.drawable.bg_chat_dis_active, StringUtils.parseName(otherusername)+"的动态",
////			    					BeemApplication.getInstance().mGpsAddr,
////			    					R.drawable.addynamics,//ic_menu_invite  ic_topbar_profile
////			    					new OnMiddleImageButtonClickListener(),
////			    					R.drawable.return2,
////			    					new OnRightImageButtonClickListener());
//			    		}
//			    		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++InitialFeeds1 ismyself="+ismyself);
////			    		String username = "";
////			    		String otherusername = "";
//			    		String longitude = String.valueOf(SpiceApplication.getInstance().mLongitude);
//			    		String latitude = String.valueOf(SpiceApplication.getInstance().mLatitude);
//			    		String memo = "";
//			    		String str_pictures = "";
//			    		String str_faner = "";
////			    		String time = com.stb.isharemessage.utils.TextUtils.dateToMillis(new Date());
//			    		String time = "";
////			    		String geolocation = BeemApplication.getInstance().mGpsAddr;
//			    		String geolocation = "";
////			    		int startIndex = 0;
////			    		int numResults = 100;
//			    		
//			    		int atIndex = otherusername.lastIndexOf("@");
//			    		if(atIndex<0)
//			    			;
//			    		else
//			    			otherusername = StringUtils.parseName(otherusername);
//			    		myHashMap = mXmppFacade.getDynamicsItems(mtype,
//			    	    		dynamicid,
//			    	    		username2,
//			    	    		otherusername,//StringUtils.parseName(otherusername)
//			    	    		longitude,
//			    	    		latitude,
//			    	    		memo,
//			    	    		str_pictures,
//			    	    		str_faner,
//			    	    		time,
//			    	    		geolocation,
//			    	    		currentPage*numberresult,//startIndex
//			    	    		numberresult);//numResults
//			    		if(myHashMap!=null)
//			    		hashMap = myHashMap.getMap();
//			    		if(hashMap!=null){
//			    		Set set = hashMap.entrySet() ;
//			    		java.util.Iterator it = hashMap.entrySet().iterator();
//			    		while(it.hasNext()){
//				    		java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
//				    		CTTotal = Integer.parseInt((String)entry.getKey());// 返回与此项对应的键
//				    		results = (List<DynamicsItemParcelable>)entry.getValue(); //返回与此项对应的值
//				    		
//				    		pageCount = CTTotal%numberresult==0? CTTotal/numberresult-1 : CTTotal/numberresult;
//	                        //System.out.println(entry.getValue());
//			    		} 
//			    		totalnumber = myHashMap.getTotalnumber();
//			    		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++CTTotal="+CTTotal);
//			    		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++totalnumber="+totalnumber);
//			    		}
//			    		if(results!=null && results.size()!=0){
//			    			errorType = 5;
//			    			for(int i=0;i<results.size();i++){
//			    				dynamicsItemParcelable = (DynamicsItemParcelable)results.get(i);
//			    				feed = new Feed(dynamicsItemParcelable.getId()+"","",dynamicsItemParcelable.getTime(), 
//			    						dynamicsItemParcelable.getMemo(), 
//			    						dynamicsItemParcelable.getPictures(),
//			    						dynamicsItemParcelable.getFaner(), 
//			    						dynamicsItemParcelable.getDistance(),
//										3,//commentCount
//										dynamicsItemParcelable.getEmail(),
//										dynamicsItemParcelable.getName(),
//										dynamicsItemParcelable.getUid());
//			    				
////			    				mFeeds.add(feed);
//			    				mFeeds_temp.add(feed);
//			    			}
//			    		}else{
//			    			if(results!=null && results.size()==0)
//			    				errorType = 0;
//			    			else
//			    				errorType = 6;
//			    		}
//			    		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++mFeeds.size()="+mFeeds_temp.size());
//			    	}else
//			    		errorType = 1;
//		    	}else
//		    		errorType = 2;
//		    	
//		    }catch (RemoteException e) {
//		    	errorType = 3;
//		    	e.printStackTrace();
//		    	
//		    } catch (Exception e){
//		    	errorType = 3;
//		    	e.printStackTrace();
//		    }
//		    return true;
//		}else{
//	    	errorType = 4;
//	    }
//		return false;
//	}
	
	
    private boolean InitialFeeds2( ){//page=1 keystr=""
//    	showCustomToast("initGeGroupMembers1");
    	Log.e("================GroupDetailsActivity.java ================", "++++++++++++++initGeGroupMembers1111++++++++++++++");
		try{
			if(BeemConnectivity.isConnected(getApplicationContext())){
				Log.e("================GroupDetailsActivity.java ================", "++++++++++++++initGeGroupMembers2222++++++++++++++");
		    if(mXmppFacade!=null 
					&& mXmppFacade.getXmppConnectionAdapter()!=null 
					&& mXmppFacade.getXmppConnectionAdapter().getAdaptee()!=null//&& !mXmppFacade.getXmppConnectionAdapter().getAdaptee().isAuthenticated()
//					&& mXmppFacade.getXmppConnectionAdapter().getAdaptee().isConnected()
//					&& mXmppFacade.getXmppConnectionAdapter().getAdaptee().isAuthenticated()
//					&& mXmppFacade.getXmppConnectionAdapter().getAdaptee().isAlive()
					){
		    		Log.e("================GroupDetailsActivity.java ================", "++++++++++++++initGeGroupMembers3333++++++++++++++");
//			    	if(mtype==null 
//		    				|| mtype.equalsIgnoreCase("null")
//		    				|| mtype.length()==0)
		    			mtype = "1";
		    		String dynamicid = "";
		    		String longitude = String.valueOf(SpiceApplication.getInstance().mLongitude);
		    		String latitude = String.valueOf(SpiceApplication.getInstance().mLatitude);
		    		String memo = "";
		    		String str_pictures = "";
		    		String str_faner = "";
		    		String time = "";
		    		String geolocation = "";
//		    		5000*1000+""
//		    		currentPage*numberresult,//startIndex
//    	    		numberresult);//numResults
		    		
		    	    DynamicsIQ reqXML = new DynamicsIQ();
		            reqXML.setId("1234567890");
		            reqXML.setApikey("abcdefghijklmnopqrstuvwxyz");
		            reqXML.setMtype(mtype);
		            reqXML.setDynamicid(dynamicid);
		            reqXML.setUsername(StringUtils.parseBareAddress2(mXmppFacade.getXmppConnectionAdapter().getJID()));//2
		            reqXML.setOtherusername(otherusername);
		            reqXML.setLongitude(longitude);
		            reqXML.setLatitude(latitude);
		            reqXML.setMemo(memo);
		            reqXML.setPictures(str_pictures);
		            reqXML.setFaner(str_faner);
		            reqXML.setTime(time);
		            reqXML.setGeolocation(geolocation);
		            reqXML.setRadius(5000*1000+"");
		            reqXML.setStartIndex(currentPage*numberresult+"");
		            reqXML.setNumResults(numberresult+"");
		            
		            
		            
		            SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
		    	    String username = settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "");

		            String uuid = mXmppFacade.getXmppConnectionAdapter().getAdaptee().getUUID(this,username);
//		            reqXML.setUuid(uuid);
	//	            String hashcode = "";//apikey+username(uid)+time 使用登录成功后返回的sessionid作为密码做3des运算
		            String hash_dest_src = "abcdefghijklmnopqrstuvwxyz"+ StringUtils.parseBareAddress2(mXmppFacade.getXmppConnectionAdapter().getJID())+time;
		            String hash_dest = EncryptionUtil.getHash2(hash_dest_src, "SHA");
		            reqXML.setHashcode(hash_dest);
		            reqXML.setType(IQ.Type.SET);
		            String elementName = "dynamicsiq"; 
		    		String namespace = "com:stb:dynamicsiq";
		    		DynamicsIQResponseProvider provider = new DynamicsIQResponseProvider();
		            Packet rt =  mXmppFacade.getXmppConnectionAdapter().excute(reqXML, "dynamicsiq", "com:stb:dynamicsiq", provider);
		            
		            if(rt!=null){
		                if (rt instanceof DynamicsIQResponse) {
		                	final DynamicsIQResponse dynamicsIQResponse = (DynamicsIQResponse) rt;
	
		                    if (dynamicsIQResponse.getChildElementXML().contains(
		                            "com:stb:dynamicsiq")) {
	//	    					MainActivity.this.runOnUiThread(new Runnable() {
	//		                    	
	//    							@Override
	//    							public void run() {
	//    								showCustomToast("服务器应答消息："+contactGroupListIQResponse.toXML().toString());
	//    							}
	//    						});
		                        String Id = dynamicsIQResponse.getId();
		                        String Apikey = dynamicsIQResponse.getApikey();
		                        try{
		                        	CTTotal = Integer.parseInt(dynamicsIQResponse.getCttotal());
		                        	totalnumber = Integer.parseInt(dynamicsIQResponse.getTotalnumber());
		                        	pageCount = CTTotal%numberresult==0? CTTotal/numberresult-1 : CTTotal/numberresult;
		                        }catch(Exception e){
		                        	CTTotal = 0;
		                        	totalnumber = 0;
		                        }
		                        results = dynamicsIQResponse.getDynamics();
					    		if(results!=null && results.size()!=0){
					    			errorType = 5;
					    			for(int i=0;i<results.size();i++){
					    				dynamicsItem = (DynamicsItem)results.get(i);
					    				feed = new Feed(dynamicsItem.getId()+"","",dynamicsItem.getTime(), 
					    						dynamicsItem.getMemo(), 
					    						dynamicsItem.getPictures(),
					    						dynamicsItem.getFaner(), 
					    						dynamicsItem.getDistance(),
												3,//commentCount
												dynamicsItem.getEmail(),
												dynamicsItem.getName(),
												dynamicsItem.getUser_id());
					    				
//					    				mFeeds.add(feed);
					    				mFeeds_temp.add(feed);
					    			}
					    			return true;
					    		}else{
					    			if(results!=null && results.size()==0)
					    				errorType = 0;
					    			else
					    				errorType = 6;
					    		}
//		                        String retcode = dynamicsIQResponse.getRetcode();
//		                        memo = dynamicsIQResponse.getMemo();
//		                        if(retcode.equalsIgnoreCase("0000")){
//		                        	errorType = 0;
//		                        	return true;
//		                        }
//		                        else if(retcode.equalsIgnoreCase("0002"))
//		                        	errorType = 6;
//		                        else
//		                        	errorType = 5;
		                        
		                    }
		                } 
		            }
		    		errorType = 1;

		    }else
		    	errorType = 1;
		    
			}else
				errorType = 4;
		}catch(RemoteException e){
			e.printStackTrace();
			errorType = 2;
		}catch(Exception e){
			e.printStackTrace();
			errorType = 3;
		}
		return false;
    }
	
	private String[] errorMsg = new String[]{"没有相关记录.",
			"服务连接中1-1,请稍候再试.",
			"服务连接中1-2,请稍候再试.",
			"服务连接中1-3,请稍候再试.",
			"网络连接不可用,请检查你的网络设置.",
			"",
			"请求异常,稍候重试!"};
	private int errorType = 5;
	
	private String myjid = "";
    @Override
    protected void onResume() {
		super.onResume();
		Intent intent = getIntent(); 
		otherusername = intent.getStringExtra("otherusername");
		from = intent.getStringExtra("mFrom");
		mtype = intent.getStringExtra("mtype");
		if(mtype==null || mtype.equalsIgnoreCase("null"))
			mtype = "";
		mAdapter.setOtherusername(otherusername);
		mAdapter.setMType(mtype);
		roomname = intent.getStringExtra("roomname");
		if(roomname==null || roomname.equalsIgnoreCase("null"))
			roomname = "";
    	nickname = intent.getStringExtra("nickname");
		if(nickname==null || nickname.equalsIgnoreCase("null"))
			nickname = "";
    	name = intent.getStringExtra("name");
		if(name==null || name.equalsIgnoreCase("null"))
			name = "";
    	headimg = intent.getStringExtra("headimg");
		if(headimg==null || headimg.equalsIgnoreCase("null"))
			headimg = "";
    	myheadimg = intent.getStringExtra("myheadimg");
		if(myheadimg==null || myheadimg.equalsIgnoreCase("null"))
			myheadimg = "";
    	myusername = intent.getStringExtra("myusername");
		if(myusername==null || myusername.equalsIgnoreCase("null"))
			myusername = "";
    	
    	if(from!=null 
    			&& !from.equalsIgnoreCase("null") 
    			&& from.length()!=0)
    		try{
    			mFrom = Integer.parseInt(from);
    		}catch(Exception e){
    			mFrom = 0;
    		}
		myjid = intent.getStringExtra("myjid");
		if(myjid==null || myjid.equalsIgnoreCase("null"))
			myjid = "";	
//		mHeaderLayout.setDefaultTitle(otherusername+"的动态", null);
		
		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++myjid="+myjid);
		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++otherusername="+otherusername);	
		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++myjid.equals(otherusername)="+(myjid.equals(otherusername)));
    	if(mtype!=null 
				&& !mtype.equalsIgnoreCase("null")
				&& mtype.length()!=0
				&& mtype.equals("1")){
			Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++ismyself2="+ismyself+" handler2");
			mHeaderLayout.init(HeaderStyle.TITLE_CHAT);
			mHeaderLayout.setTitleChat(R.drawable.ic_chat_dis_1,
					R.drawable.bg_chat_dis_active, "Show一下",
					SpiceApplication.getInstance().mGpsAddr,
					R.drawable.addynamics,//ic_menu_invite  ic_topbar_profile
					new OnMiddleImageButtonClickListener(),
					R.drawable.return2,
					new OnRightImageButtonClickListener());
    	}else{
    		String temp = otherusername;
    		int atIndex = otherusername.lastIndexOf("@");
    		if(atIndex<0)
    			;
    		else
    			temp = StringUtils.parseName(otherusername);
    		
			if(!((StringUtils.parseName(myjid)).equals(temp))){
				if(name!=null
						&& !name.equalsIgnoreCase("null")
						&& name.length()!=0)
					temp = name;
				
		    	mHeaderLayout.init(HeaderStyle.TITLE_RIGHT_IMAGEBUTTON);	
		        mHeaderLayout.setTitleRightImageButton(temp+"的动态", SpiceApplication.getInstance().mGpsAddr,
		    				R.drawable.return2,
		    				new OnRightImageButtonClickListener());
	        
	    	}else{
	    		if(name!=null
						&& !name.equalsIgnoreCase("null")
						&& name.length()!=0)
					temp = name;
				Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++ismyself2="+ismyself+" handler2");
				mHeaderLayout.init(HeaderStyle.TITLE_CHAT);
				mHeaderLayout.setTitleChat(R.drawable.ic_chat_dis_1,
						R.drawable.bg_chat_dis_active, temp+"的动态",
						SpiceApplication.getInstance().mGpsAddr,
						R.drawable.addynamics,//ic_menu_invite  ic_topbar_profile
						new OnMiddleImageButtonClickListener(),
						R.drawable.return2,
						new OnRightImageButtonClickListener());
			}
    	}
		Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++otherusername="+otherusername);
		if (!mBinded){
			mBinded = bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
		}
    }
    @Override
    protected void onPause() {
		super.onPause();
//		if (mBinded) {
//			unbindService(mServConn);
//			mBinded = false;
//		}
    }
    @Override
    protected void onDestroy() {
		super.onDestroy();
	    try{//网络状态相关
		    if(mXmppFacade!=null && mXmppFacade.getXmppConnectionAdapter()!=null)
		    	mXmppFacade.getXmppConnectionAdapter().unRegisterConnectionStatusCallback();
	    }catch (RemoteException e) {
	    	e.printStackTrace();
	    }
		if (mBinded) {
			unbindService(mServConn);
			mBinded = false;
		}
		//网络状态start
		unregisterReceiver(mNetWorkReceiver); // 删除广播
		if(tm!=null){
			tm.listen(myPhoneCallListener,PhoneStateListener.LISTEN_NONE);//取消监听即可
			tm = null;
		}
		if(myPhoneCallListener!=null)
			myPhoneCallListener = null;
		//网络状态end
//		this.unregisterReceiver(mReceiver);//原来的网络状态注释掉
    }
    private class BeemServiceConnection implements ServiceConnection {
    	private Context mContext;
		/**
		 * constructor.
		 */
		public BeemServiceConnection(Context context) {
			mContext = context;
		}
	
		/**
		 * {@inheritDoc}
		 */
		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
		    mXmppFacade = IXmppFacade.Stub.asInterface(service);
		    if(mXmppFacade!=null){
		    mBinded = true;//20130804 added by allen
	    	try{
	    		mXmppFacade.getXmppConnectionAdapter().registerConnectionStatusCallback(OtherFeedListActivity.this);//网络状态相关
	    	}catch(Exception e){}
		    }
//			displayCurrentAvatar(mContext);
		    Log.e("MMMMMMMMMMMM20140828OtherFeedListActivityMMMMMMMMMMMM", "++++++++++++++onServiceConnected"+otherusername);
//		    getStatus();
		}
	
		/**
		 * {@inheritDoc}
		 */
		@Override
		public void onServiceDisconnected(ComponentName name) {
			 try{//网络状态相关
				    if(mXmppFacade!=null && mXmppFacade.getXmppConnectionAdapter()!=null)
				    	mXmppFacade.getXmppConnectionAdapter().unRegisterConnectionStatusCallback();
			    }catch (RemoteException e) {
			    	e.printStackTrace();
			    }
			mBinded = false;
		    mXmppFacade = null;
		}
    }
	protected class OnMiddleImageButtonClickListener implements
	onMiddleImageButtonClickListener {

		@Override
		public void onClick() {
        	intent = new Intent(OtherFeedListActivity.this, AddDynamicsActivity.class);
        	intent.putExtra("otherusername", otherusername);
        	intent.putExtra("JIDWithRes", otherusername);
        	intent.putExtra("roomname", roomname);
        	intent.putExtra("nickname", nickname);
        	intent.putExtra("name", name);
        	intent.putExtra("headimg", headimg);
        	intent.putExtra("myheadimg", myheadimg);
        	intent.putExtra("myusername", myusername);
        	intent.putExtra("myjid", myjid);
        	intent.putExtra("mFrom", "1");
        	intent.putExtra("mtype", mtype);
        	
        	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
		    finish();
		}
	}
	private int mFrom = 0;
	private String from = "";
	private Intent intent;
	private String roomname = "";
	private String nickname = "";
	private String name = "";
	private String headimg = "";
	private String myheadimg = "";
	private String myusername = "";
	private class OnRightImageButtonClickListener implements
	onRightImageButtonClickListener {
	
		@Override
		public void onClick() {
			switch(mFrom){
			case 0:
				intent = new Intent(OtherFeedListActivity.this, ContactFrameActivity.class);//ContactListPullRefListActivity
				startActivity(intent);
			break;
			case 1://ProfileActivity
	        	intent = new Intent(OtherFeedListActivity.this, PreferenceActivity.class);
	        	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	            startActivity(intent);
				break;
			case 2://OtherProfileActivity
				intent = new Intent(OtherFeedListActivity.this, OtherProfileActivity.class);
	        	intent.putExtra("JIDWithRes", otherusername);
	        	intent.putExtra("roomname", roomname);
	        	intent.putExtra("nickname", nickname);
	        	intent.putExtra("name", name);
	        	intent.putExtra("headimg", headimg);
	        	intent.putExtra("myheadimg", myheadimg);
	        	intent.putExtra("myusername", myusername);
				break;
			case 3://GroupProfileActivity
				intent = new Intent(OtherFeedListActivity.this, GroupDetailsActivity.class);
	        	intent.putExtra("JIDWithRes", otherusername);
	        	intent.putExtra("roomname", roomname);
	        	intent.putExtra("nickname", nickname);
	        	intent.putExtra("name", name);
	        	intent.putExtra("headimg", headimg);
	        	intent.putExtra("myheadimg", myheadimg);
	        	intent.putExtra("myusername", myusername);
				break;				
		    default:
				intent = new Intent(OtherFeedListActivity.this, ContactFrameActivity.class);//ContactListPullRefListActivity
				startActivity(intent);
		    	break;
			}
			OtherFeedListActivity.this.finish();
		}
	}
	
	
	//百度定位start
//	protected FlippingLoadingDialog mLoadingDialog;
//	protected void showLoadingDialog(String text) {
//		if (text != null) {
//			mLoadingDialog.setText(text);
//		}
//		mLoadingDialog.show();
//	}
//
//	protected void dismissLoadingDialog() {
//		if (mLoadingDialog.isShowing()) {
//			mLoadingDialog.dismiss();
//		}
//	}
	public LocationClient mLocationClient;
	public LocationClientOption option;
//	public GeofenceClient mGeofenceClient;
	public MyLocationListener mMyLocationListener;
	public double mLongitude;
	public double mLatitude;
	public String mGpsAddr;
	/**
	 * 实现定位回调监听
	 */
	public class MyLocationListener implements BDLocationListener {

		@Override
		public void onReceiveLocation(BDLocation location) {
			int result = 9;
			//Receive Location 
			if(location==null){
				dismissLoadingDialog();
				showCustomToast("定位失败...");
				return;
			}if(location!=null
					&&location.getLongitude()!=0.0
					&& location.getLatitude()!=0.0
					&& location.getAddrStr()!=null){
				result = 8;
			mLongitude = location.getLongitude();
			mLatitude = location.getLatitude();
			mGpsAddr = location.getAddrStr();
			SpiceApplication.getInstance().mLongitude = mLongitude;
			SpiceApplication.getInstance().mLatitude = mLatitude;
			SpiceApplication.getInstance().mGpsAddr = mGpsAddr;
			Log.e("※※※※※※20140725地理位置※※※※※※", "※※※※※※经度:" + mLongitude + ",纬度:" + mLatitude + ",地址:" + mGpsAddr);
			
			StringBuffer sb = new StringBuffer(256);
			sb.append("time : ");
			sb.append(location.getTime());
			sb.append("\nerror code : ");
			sb.append(location.getLocType());
			sb.append("\nlatitude : ");
			sb.append(location.getLatitude());
			sb.append("\nlontitude : ");
			sb.append(location.getLongitude());
			sb.append("\nradius : ");
			sb.append(location.getRadius());
			if (location.getLocType() == BDLocation.TypeGpsLocation){
				sb.append("\nspeed : ");
				sb.append(location.getSpeed());
				sb.append("\nsatellite : ");
				sb.append(location.getSatelliteNumber());
				sb.append("\ndirection : ");
				sb.append("\naddr : ");
				sb.append(location.getAddrStr());
				sb.append(location.getDirection());
			} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
				sb.append("\naddr : ");
				sb.append(location.getAddrStr());
				//运营商信息
				sb.append("\noperationers : ");
				sb.append(location.getOperators());
			}
			Log.e("※※※※※※20140725BaiduLocationApiDem※※※※※※", sb.toString());
			}
			mHandler2.sendEmptyMessage(result);
			mLocationClient.stop();
			
		}
	}
	private void InitLocation(){
		option = new LocationClientOption();
		option.setLocationMode(LocationMode.Hight_Accuracy);//设置定位模式Hight_Accuracy,Battery_Saving,Device_Sensors
		option.setOpenGps(true);
		
		option.setCoorType("bd09ll");//返回的定位结果是百度经纬度，默认值gcj02,bd09ll,bd09
		option.setScanSpan(5000);//设置发起定位请求的间隔时间为5000ms
		option.setIsNeedAddress(true);//返回的定位结果包含地址信息
		mLocationClient.setLocOption(option);
	}
    //百度定位end
	
	
	//网络状态 start
		@Override
		public void connectionStatusChanged(int connectedState, String reason) {
			Log.e("MMMMM20140604MMMMMMMMMMMM", "++++++++++++++connectionStatusChanged0++++++++++++");
			switch (connectedState) {
			case 0://connectionClosed
				mHandler3.sendEmptyMessage(0);
				break;
			case 1://connectionClosedOnError
//				mConnectErrorView.setVisibility(View.VISIBLE);
//				mNetErrorView.setVisibility(View.VISIBLE);
//				mConnect_status_info.setText("连接异常!");
				mHandler3.sendEmptyMessage(1);
				break;
			case 2://reconnectingIn
//				mNetErrorView.setVisibility(View.VISIBLE);
//				mConnect_status_info.setText("连接中...");
				mHandler3.sendEmptyMessage(2);
				break;
			case 3://reconnectionFailed
//				mNetErrorView.setVisibility(View.VISIBLE);
//				mConnect_status_info.setText("重连失败!");
				mHandler3.sendEmptyMessage(3);
				break;
			case 4://reconnectionSuccessful
//				mNetErrorView.setVisibility(View.GONE);
				mHandler3.sendEmptyMessage(4);

			default:
				break;
			}
		}
		Handler mHandler3 = new Handler() {

			@Override
			public void handleMessage(android.os.Message msg) {
				super.handleMessage(msg);
				switch (msg.what) {
				case 0:
					break;

				case 1:
					mNetErrorView.setVisibility(View.VISIBLE);
					if(BeemConnectivity.isConnected(mContext))
					mConnect_status_info.setText("连接异常!");
					break;

				case 2:
					mNetErrorView.setVisibility(View.VISIBLE);
					if(BeemConnectivity.isConnected(mContext))
					mConnect_status_info.setText("连接中...");
					break;
				case 3:
					mNetErrorView.setVisibility(View.VISIBLE);
					if(BeemConnectivity.isConnected(mContext))
					mConnect_status_info.setText("重连失败!");
					break;
					
				case 4:
					mNetErrorView.setVisibility(View.GONE);
					String udid = "";
					String partnerid = "";
					try{
						udid = mXmppFacade.getXmppConnectionAdapter().getAdaptee().UDID;
						partnerid = mXmppFacade.getXmppConnectionAdapter().getMService().getPartnerid();
					}catch(Exception e){
						e.printStackTrace();
					}
//					udidTextView.setText("udid="+udid);
//					partneridEditText.setText(partnerid);
//					getContactList();//20141025 added by allen
					break;
				case 5:
					mNetErrorView.setVisibility(View.VISIBLE);
					mConnect_status_info.setText("当前网络不可用，请检查你的网络设置。");
					break;
				case 6:
					if(mXmppFacade!=null 
//							&& mXmppFacade.getXmppConnectionAdapter()!=null 
//							&& mXmppFacade.getXmppConnectionAdapter().getAdaptee()!=null//&& !mXmppFacade.getXmppConnectionAdapter().getAdaptee().isAuthenticated()
//							&& mXmppFacade.getXmppConnectionAdapter().getAdaptee().isConnected()
//							&& mXmppFacade.getXmppConnectionAdapter().getAdaptee().isAuthenticated()
							&& BeemConnectivity.isConnected(mContext)){
						
					}else{
						mNetErrorView.setVisibility(View.VISIBLE);
						if(BeemConnectivity.isConnected(mContext))
						mConnect_status_info.setText("网络可用,连接中...");
					}
					break;	
				}
			}

		};
		private BroadcastReceiver mNetWorkReceiver = new BroadcastReceiver() {
	        @Override
	        public void onReceive(Context context, Intent intent) {
	            String action = intent.getAction();  
	            if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {  
	                Log.d("PoupWindowContactList", "网络状态已经改变");  
//	                connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);  
//	                info = connectivityManager.getActiveNetworkInfo();    
//	                if(info != null && info.isAvailable()) {  
//	                    String name = info.getTypeName();  
//	                    Log.d(tag, "当前网络名称：" + name);  
//	                    //doSomething()  
//	                } else {  
//	                    Log.d(tag, "没有可用网络");  
//	                  //doSomething()  
//	                }  
	                if(BeemConnectivity.isConnected(context)){
//	                	mNetErrorView.setVisibility(View.GONE);
//	                	isconnect = 0;
	                	mHandler3.sendEmptyMessage(6);//4
	                }else{
//	                	mNetErrorView.setVisibility(View.VISIBLE);
//	                	isconnect = 1;
	                	mHandler3.sendEmptyMessage(5);
	                	Log.d("PoupWindowContactList", "当前网络不可用，请检查你的网络设置。");
	                }
	            } 
	        }
		};
		
		private boolean phonestate = false;//false其他， true接起电话或电话进行时 
	    /* 内部class继承PhoneStateListener */
	    public class exPhoneCallListener extends PhoneStateListener
	    {
	        /* 重写onCallStateChanged
	        当状态改变时改变myTextView1的文字及颜色 */
	        public void onCallStateChanged(int state, String incomingNumber)
	        {
	          switch (state)
	          {
	            /* 无任何状态时 :说明没有拨打电话的界面的时候，也就是在拨打电话前和挂电话后的情况*/
	            case TelephonyManager.CALL_STATE_IDLE:
	            	Log.e("================20131216 无任何电话状态时================", "无任何电话状态时");
	            	if(phonestate){
	            		onPhoneStateResume();
	            	}
	            	phonestate = false;
	              break;
	            /* 接起电话时 :至少有一个电话存在、拨出或激活、接听，而没有一个电话在通话或等待的状态*/
	            case TelephonyManager.CALL_STATE_OFFHOOK:
	            	Log.e("================20131216 接起电话时================", "接起电话时");
	            	onPhoneStatePause();
	            	phonestate = true;
	              break;
	            /* 电话进来时 :在通话的过程中*/
	            case TelephonyManager.CALL_STATE_RINGING:
//	              getContactPeople(incomingNumber);
	            	Log.e("================20131216 电话进来时================", "电话进来时");
//	            	onBackPressed();
	            	onPhoneStatePause();
	            	phonestate = true;
	              break;
	            default:
	              break;
	          }
	          super.onCallStateChanged(state, incomingNumber);
	        }
	    }
	    
	    protected void onPhoneStatePause() {
//			super.onPause();
	    	try{
//	    		try {
//	    		    if (mRoster != null) {
//	    			mRoster.removeRosterListener(mBeemRosterListener);
//	    			mRoster = null;
//	    		    }
//	    		} catch (RemoteException e) {
//	    		    Log.d("ContactList", "Remote exception", e);
//	    		}
				if (mBinded) {
					getApplicationContext().unbindService(mServConn);
				    mBinded = false;
				}
				mXmppFacade = null;
	    	}catch(Exception e){
	    		e.printStackTrace();
	    	}
	    }
	    
	    protected void onPhoneStateResume() {
//			super.onResume();
	    	try{
			if (!mBinded){
//			    new Thread()
//			    {
//			        @Override
//			        public void run()
//			        {
			    mBinded = getApplicationContext().bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);

//			        }
//			    }.start();		    
			}
//			if (mBinded){
//				mImageFetcher.setExitTasksEarly(false);
//			}
	    	}catch(Exception e){
	    		e.printStackTrace();
	    	}
	    }
	    
	    /*
	     * 打开设置网络界面
	     * */
	    public static void setNetworkMethod(final Context context){
	        //提示对话框
	        AlertDialog.Builder builder=new AlertDialog.Builder(context);
	        builder.setTitle("网络设置提示").setMessage("网络连接不可用,是否进行设置?").setPositiveButton("设置", new DialogInterface.OnClickListener() {
	            
	            @Override
	            public void onClick(DialogInterface dialog, int which) {
	                // TODO Auto-generated method stub
	                Intent intent=null;
	                //判断手机系统的版本  即API大于10 就是3.0或以上版本 
	                if(android.os.Build.VERSION.SDK_INT>10){
	                    intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
	                }else{
	                    intent = new Intent();
	                    ComponentName component = new ComponentName("com.android.settings","com.android.settings.WirelessSettings");
	                    intent.setComponent(component);
	                    intent.setAction("android.intent.action.VIEW");
	                }
	                context.startActivity(intent);
	            }
	        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
	            
	            @Override
	            public void onClick(DialogInterface dialog, int which) {
	                // TODO Auto-generated method stub
	                dialog.dismiss();
	            }
	        }).show();
	    }
		//网络状态 end
}
